#include "stdafx.h"

HHOOK g_hMouse=NULL;
HHOOK g_hKeyboard=NULL;

#pragma data_seg("MySec")
HWND g_hWnd=NULL;
#pragma data_seg()

//#pragma comment(linker,"/section:MySec,RWS")
/*HINSTANCE g_hInst;

BOOL WINAPI DllMain(
HINSTANCE hinstDLL,  // handle to the DLL module
DWORD fdwReason,     // reason for calling function
LPVOID lpvReserved   // reserved
)
{
g_hInst=hinstDLL;
}*/

LRESULT CALLBACK MouseProc(
						   int nCode,      // hook code
						   WPARAM wParam,  // message identifier
						   LPARAM lParam   // mouse coordinates
						   )
{
	if(PMOUSEHOOKSTRUCT(lParam)->hwnd == g_hWnd)
		return 1;
	else
		return CallNextHookEx(g_hMouse, nCode, wParam, lParam);
}

LRESULT CALLBACK KeyboardProc(
							  int code,       // hook code
							  WPARAM wParam,  // virtual-key code
							  LPARAM lParam   // keystroke-message information
							  )
{
	if(VK_F2==wParam)
	{
		UnhookWindowsHookEx(g_hMouse);
		UnhookWindowsHookEx(g_hKeyboard);
	}
	return 1;
}

void SetHook(HWND hwnd)
{
	g_hWnd=hwnd;
	g_hMouse=SetWindowsHookEx(WH_MOUSE,MouseProc,GetModuleHandle("inNet"),0);
	g_hKeyboard=SetWindowsHookEx(WH_KEYBOARD,KeyboardProc,GetModuleHandle("inNet"),0);
}